﻿@{
    ViewData["Title"] = "添加角色";
}
<div class="layui-fluid">
    <div class="layui-card layui-form" lay-filter="layuiadmin-form-list" id="layuiadmin-form-list" style="padding: 20px 30px 0 0;">
        <div class="layui-card-body">
            <div class="layui-form-item">
                <label for="RoleCode" class="layui-form-label">
                    <span class="x-red">*</span>角色代码
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="RoleCode" name="RoleCode" value="@Model.RoleCode" required="" lay-verify="required"
                           autocomplete="off" class="layui-input">
                    <input type="hidden" name="Id" value="@Model.Id" />
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="RoleName" class="layui-form-label">
                    <span class="x-red">*</span>角色名称
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="RoleName" name="RoleName" value="@Model.RoleName"  autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="RoleDesc" class="layui-form-label">
                    <span class="x-red">*</span>角色描述
                </label>
                <div class="layui-input-inline">
                    <textarea rows="3" cols="40" name="RoleDesc" id="RoleDesc" class="layui-textarea">@Model.RoleDesc</textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="IsDefault" class="layui-form-label">
                    <span class="x-red">*</span>是否默认
                </label>
                <div class="layui-input-inline">
                    <input type="radio" name="IsDefault" value="Y" title="是">
                    <input type="radio" name="IsDefault" value="N" title="否" checked="checked">
                </div>
            </div>
            <div class="layui-form-item" style="text-align:center;">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="layuiadmin-form-submit" id="layuiadmin-form-submit">立即提交</button>
                    <button class="layui-btn layui-btn-danger" type="button" onclick="onClose()">
                        关闭
                    </button>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    layui.config({
        base: '/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form'], function () {
        var $ = layui.$
            , form = layui.form
            , admin = layui.admin;
        form.render(null, 'layuiadmin-form-list');
        //监听提交
        form.on('submit(layuiadmin-form-submit)', function (data) {
            var field = data.field; //获取提交的字段

            //请求登入接口
            admin.req({
                url: '/Role/Save' //实际使用请改成服务端真实接口
                , method: 'post'
                , data: field
                , done: function (res) {
                    layer.msg(res.msg, {
                        offset: '50px'
                        , icon: 1
                        , time: 3000
                    }, function () {
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layui.table.reload('LAY-role-list'); //重载表格
                        parent.layer.close(index); //再执行关闭
                    });
                }
            });
        });

        var Id = $.getQueryValue("Id");
        if (Id != undefined && Id != "") {
            layui.admin.req({
                url: '/Role/Get'
                , method: 'post'
                , data: "Id=" + Id
                , done: function (res) {
                    $.InitFormByName("layuiadmin-form-list", res.data);
                    layui.form.render(null, 'layuiadmin-form-list');
                }
            });
        }
    })

    function onClose() {
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    }
</script>
